<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>tomcat性能优化</title>
	<!--[if IE]>
		<script type="text/javascript">
			(function(){
				var b=("abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video").split(","),a=b.length;while(a--){document.createElement(b[a])}})();
		</script>
	<![endif]-->
  <style>
  	header, footer, nav, section, article {display:block;}<!--HTML5标签--> 
  	body{width:100%;height:100%;font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;font-size:12px;}
  	A{text-decoration:none;color:#34638c}
  	.mod-topbar{
  		z-index:1203;
  		position:fixed;
  		padding-bottom:0px;
  		height:40px;top:0px;
  		right:0px;
  		left:0px;
  		_height:38px;
  		_position:absolute;
  		background:url() repeat-x left top	
  	}
  	.mod-topbar .mod-topbar-bgframe{
  		border-bottom:medium none;
  		position:absolute;
  		filter:alpha(opacity=0); BORDER-LEFT: medium none;
  		width:100%;
  		height:40px;
  		border-top:medium none;
  		border-right:medium none;
  		opacity:0;
  	}
  	.mod-topbar .mod-topbar-pseudo-real{
  		background-color:#3fa7cb;
  		background:none transparent scroll repeat 0% 0%;
  	}
  	.clearfix:after{
  		height:0px;
  		clear:both;
  		content:'\20';
  	}
  	.clearfix{
  		zoom:1;
  	}
  	.mod-topbar .wrapper-box{
  		position:relative;
  		padding-bottom:0px;
  		margin:0px auto;
  		width:980px;
  		height:35px;
  	}
  	.mod-topbar .left-box{
  		float:left;
  		padding-top:3px;
  	}
  	.mod-topbar .center-box{
  		float:left;
  		heght:35px;
  		margin-left:50px
  	}
  	.mod-topbar .right-box{
  		margin-right:-7px;
  		float:right;
  		heght:35px;
  	}
  	.mod-topbar .logo-box{
  		float:left;
  		margin-left:10px;
  	}
  	.mod-topbar .q-logo{
  		width:93px;
  		height:30px;
  		_background-image:none;
  		background:url() no-repeat left top
  	}
  	.fontcls{font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;font-size:12px}
  	.fontcls14{font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;font-size:14px}
  	.fontcls16{font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;font-size:16px}
  	.fontcls50{font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;font-size:50px}
	.wordwrap {word-wrap:break-word;word-break:break-all;}  	
  	.mod-page-body{
  		min-height:100%;
  		height:auto;
  		_height:100%;
  		zoom:1;
  		color:#454545;
  	}
  	.mod-page-body .mod-page-main{
  		padding-bottom:85px;
  		padding-top:36px;
  	}
  	.mod-page-body .mod-page-main .x-page-container{
  		padding-bottom:0px;
  		margin:0px;
  		padding-left:0px;
  		padding-right:0px;
  		zoom:1;
  		padding-top:0px;
  	}
  	.grid-98{margin:0px auto;overflow:hidden;width:980px}
  	.grid-80{margin:0px auto;overflow:hidden;width:800px}
  	.mod-topspaceinfo{padding-bottom：45px;padding-left:0px;padding-right:0px;padding-top:45px}
  	.mod-topspaceinfo H1{padding-left:10px}
  	.mod-topspaceinfo H1 A{color:#555;font-size:50px}
  	.mod-topspaceinfo .mod-topspaceinfo-description{
  		line-height:2em;
  		color:#000;
  		font-size:14px;
  	}
  	.mod-content{
  		background-image:url(); 
  		BORDER-BOTTOM: #e1e1e1 1px solid;
  		background-color:#fff;
  		background-repeat:repeat-y;
  		background-position:center top;
  		border-top:#e1e1e1 1px solid;
  		box-shadow:0 -4px 10px #999;
  		-webkit-box-shadow:0 -4px 10px #999;
  		-moz-box-shadow:0 -4px 10px #999;
  		float:left;
  	}
  	.grid-77{
  		padding:0px;
  		margin:0px auto;
  		overflow:hidden;
  		width:770px;
  	}
  	
  	.divbutton{background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee));background: -moz-linear-gradient(top,#fff,#eee);background:-o-linear-gradient(top,#fff,#eee);filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee');background:linear-gradient(top, #fff, #eee);border:1px #ddd solid;padding:5px;display:inline-block;}
  </style>
 </head>

 <body background="imgs/untitled.bmp">
 	<jsp:include page="/front/common/header.jsp"></jsp:include>
	<section class="mod-page-body">
		<div class="mod-page-main wordwrap clearfix">
			<div class="x-page-container">
				<jsp:include page="/front/common/contentHeader.jsp"></jsp:include>
				<div class="grid-80" style="margin-top:-5px;">
					<!-- 文章区 -->
					<div style="margin-bottom:20px;margin-left:10px;_margin-left:5px;background:#fff;min-height:300px;border:#ccc 1px solid">
						<div style="padding-top:20px;padding-left:20px;padding-right:20px;">
						<div style='float:left;font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;font-size:20px;color:#515151;font-weight:normal;float:left'>
							tomcat性能优化
						</div>
						<div style='float:left;margin-left:5px'>
							<!-- Baidu Button BEGIN -->
						    <div id="bdshare" class="bdshare_t bds_tools get-codes-bdshare">
						        <span class="bds_more"></span>
						    </div>
							<script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=382910" ></script>
							<script type="text/javascript" id="bdshell_js"></script>
							<script type="text/javascript">
								document.getElementById("bdshell_js").src = "http://share.baidu.com/static/js/shell_v2.js?cdnversion=" + new Date().getHours();
							</script>
							<!-- Baidu Button END -->
						</div>
						<DIV style="float:right;"><SPAN style='color:#c5c5c5;font-size:12px;line-height:30px;font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti'>2012-07-24 19:28</SPAN></DIV>
						</div>
						<div style='padding-top:0px;padding-left:20px;padding-right:20px;margin-top:50px;line-height:20px;width:758px;font-size:14px;overflow:hidden;font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;'>
							<P>1：修改成NOI类型</P>
							<P>每个web客户端请求对于服务器端来说就一个单独的线程，客户端的请求数量增多将会导致线程数就上去了，CPU就忙着跟线程切换。</P>
							<P>而NIO则是使用单线程(单个CPU)或者只使用少量的多线程(多CPU)来接受Socket，而由线程池来处理堵塞在pipe或者队列里的请求.这样的话，只要OS可以接受TCP的连接，web服务器就可以处理该请求。大大提高了web服务器的可伸缩性。</P>
							<P><STRONG>修改成支持NIO的类型，配置如下</STRONG>：</P>
							<P>&lt;Connector&nbsp;port="8080"&nbsp;protocol="<STRONG>org.apache.coyote.http11.Http11NioProtocol</STRONG>"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connectionTimeout="20000"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirectPort="8443"&nbsp;/&gt;<BR></P>
							<P>进行测试，被打开nio配置，启动时的信息，如下：<BR>2010-2-1&nbsp;13:01:01&nbsp;org.apache.<STRONG>tomcat.util.net.NioSelectorPool&nbsp;getSharedSelector</STRONG><BR>信息:&nbsp;<STRONG>Using&nbsp;a&nbsp;shared&nbsp;selector&nbsp;for&nbsp;servlet&nbsp;write/read</STRONG><BR>2010-2-1&nbsp;13:01:01&nbsp;org.apache.coyote.<STRONG>http11.Http11NioProtocol&nbsp;init</STRONG><BR>信息:&nbsp;Initializing&nbsp;Coyote&nbsp;HTTP/1.1&nbsp;on&nbsp;http-8080</P>
							<P>&nbsp;2：线程池虚拟机优化</P>
							<P>&lt;Executor&nbsp;name="tomcatThreadPool"&nbsp;namePrefix="catalina-exec-"<BR>maxThreads="500"&nbsp;minSpareThreads="400"&nbsp;/&gt;&nbsp;&nbsp;<BR><BR>&lt;Connector&nbsp;executor="tomcatThreadPool"&nbsp;&nbsp;<BR>port="80"&nbsp;protocol="HTTP/1.1"&nbsp;&nbsp;&nbsp;<BR>connectionTimeout="20000"&nbsp;enableLookups="false"&nbsp;&nbsp;<BR>redirectPort="8443"&nbsp;URIEncoding="UTF-8"&nbsp;acceptCount="1000"&nbsp;/&gt;&nbsp;<BR><BR>修改tomcat/conf/server.xml配置文件为以上。<BR><BR>修改apache-tomcat-6.0.18/bin/catalina.bat配置文件为以下。<BR>set&nbsp;JAVA_OPTS=-Xms1024m&nbsp;-Xmx1024m&nbsp;-XX:PermSize=128M&nbsp;-XX:MaxPermSize=256m<BR>1.停用DNS查询&nbsp;<BR>server.xml里&nbsp;<BR>&lt;Connector&nbsp;<BR>port="8887"&nbsp;maxThreads="150"&nbsp;minSpareThreads="25"&nbsp;maxSpareThreads="75"&nbsp;<BR>enableLookups="false"&nbsp;redirectPort="8443"&nbsp;acceptCount="100"&nbsp;<BR>debug="0"&nbsp;connectionTimeout="20000"&nbsp;<BR>disableUploadTimeout="true"&nbsp;/&gt;&nbsp;<BR><BR>加上enableLookups="false";这样就不使用DNS查询，也不会有延迟了&nbsp;<BR>除非需要所有连接到服务器的HTTP客户端的完整主机名称&nbsp;<BR><BR>注：Connector的enableLookups性属的意义是:调用request.getRemoteHost()是否会通过DNS查询来取得远处客户端的真正主机名称。true表示会查询，false表示以字符串格式传回客户端的IP地址。默认值是:true&nbsp;<BR></P>
							
							<div style='padding-top:20px;padding-bottom:40px;padding-right:10px;font-family:"Microsoft Yahei", "微软雅黑", Tahoma, Arial, Helvetica, STHeiti;font-size:12px;color:#9f9f9f'>
								<div style="float:left;">
									<div style="float:left;background:#f5f5f5;padding-left:5px;padding-right:5px;padding-top:3px;">
										#操作系统
									</div>
									<div style="float:left;width:3px;">&nbsp;</div>
									<div style="float:left;background:#f5f5f5;padding-left:5px;padding-right:5px;padding-top:3px;">
										#操作系统
									</div>
								</div>
								
								<div style="float:right">
									<div style="float:left;color:#9f9f9f">浏览(30)</div>
									<div style="float:left;width:15px">&nbsp;</div>
									<div style="float:left"><a href="javascript:;" style="color:#9f9f9f">编辑</a></div>
									<div style="float:left;width:15px">&nbsp;</div>
									<div style="float:left"><a href="javascript:;" style="color:#9f9f9f">删除</a></div>
								</div>
							</div>
						</div>
					</div>
					<div style="margin-bottom:20px;margin-left:10px;_margin-left:5px;">
						<div class="divbutton" style="font-size:14px;float:left;cursor:pointer">
							<b>&lt;</b>&nbsp;上一篇
						</div>
						<div class="divbutton" style="font-size:14px;float:right;cursor:pointer">
							下一篇&nbsp;<b>&gt;</b>&nbsp;
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
 </body>
</html>
